/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ivanbiz.impl;

import com.ivanbiz.dao.JenisPUUDAO;
import com.ivanbiz.helper.HibernateUtil;
import com.ivanbiz.model.JenisPUU;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Expression;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author Ivan
 */
public class JenisPUUDAOImpl extends GenericDAOImpl implements JenisPUUDAO {

    public List<JenisPUU> getDataByLike(Class<JenisPUU> jenisPUU, String nomor, String tahunAwal, String tahunAkhir, String tentang, String kabProp) throws Exception {
        try {
            Session session = HibernateUtil.getSession();
            Criteria crit = session.createCriteria(JenisPUU.class);
            crit.add(Restrictions.like("nomor", "%" + nomor + "%"));
            crit.add(Restrictions.ge("tahun", tahunAwal));
            crit.add(Restrictions.le("tahun", tahunAkhir));
            crit.add(Expression.or(Restrictions.like("judulPeraturan", "%" + tentang + "%"), Restrictions.like("kabProp", "%" + kabProp + "%")));
            crit.addOrder(Order.asc("tahun"));
            crit.addOrder(Order.asc("jenis"));
            crit.addOrder(Order.asc("nomor"));
            List list = crit.list();
            return list;
        } catch (Exception e) {
            HibernateUtil.rollbackTransaction();
            throw e;
        } finally {
            HibernateUtil.closeSession();
        }
    }

    public List<JenisPUU> getDataByLike(Class<JenisPUU> jenisPUU, String nomor, String tahunAwal, String tahunAkhir, String tentang, String prop, String kab) throws Exception {
        try {
            Session session = HibernateUtil.getSession();
            Criteria crit = session.createCriteria(JenisPUU.class);
            crit.add(Restrictions.like("nomor", "%" + nomor + "%"));
            crit.add(Restrictions.ge("tahun", tahunAwal));
            crit.add(Restrictions.le("tahun", tahunAkhir));
            crit.add(Restrictions.like("judulPeraturan", "%" + tentang + "%"));
            crit.add(Expression.or(Restrictions.like("kabProp", "%" + prop + "%"), Restrictions.like("kabProp", "%" + kab + "%")));
            crit.addOrder(Order.asc("tahun"));
            crit.addOrder(Order.asc("jenis"));
            crit.addOrder(Order.asc("nomor"));
            List list = crit.list();
            return list;
        } catch (Exception e) {
            HibernateUtil.rollbackTransaction();
            throw e;
        } finally {
            HibernateUtil.closeSession();
        }
    }
}
